use serde::{Deserialize, Serialize};
use validator::Validate;
use crate::dto::point_dto::PointDto;
use crate::entity::cfg_varsystem::Model;
use crate::entity::prelude::CfgVarsystem;
use crate::entity::prj_system;

#[derive(Debug, Validate, Deserialize, Serialize, Clone)]
pub struct PrjSystemDto {
    pub id: i32,
    pub name: Option<String>,
    pub parent_id: Option<i32>,
    pub description: Option<String>,
    pub system_id: Option<i32>,
    pub model_type: Option<String>,
    // pub prj_unit_id: Option<i32>,
    // pub unit_id: Option<i32>,
    pub children: Vec<PrjSystemDto>,
    pub points: Vec<PointDto>,
}

impl PrjSystemDto {
    pub fn from_model(model: prj_system::Model, children: Vec<PrjSystemDto>, points: Vec<Model>) -> Self {
        // points to pointdtos
        let points = points.into_iter().map(|model| PointDto::from(model)).collect();

        Self {
            id: model.id,
            name: model.name,
            parent_id: model.parent_id,
            description: model.description,
            system_id: model.system_id,
            model_type: model.model_type,
            // prj_unit_id: model.prj_unit_id,
            // unit_id: model.unit_id,
            children,
            points,
        }
    }
}